package com.fivefu.core.camera.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fivefu.base.common.utils.date.DateUtils;
import com.fivefu.core.camera.entity.DbMonitorWorkorderRecord;
import com.fivefu.core.camera.mapper.DbMonitorWorkorderRecordMapper;
import com.fivefu.core.camera.services.DbMonitorWorkorderRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 工单处置记录 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-09-22 16:21:42
 */
@Service
public class DbMonitorWorkorderRecordServiceImpl extends ServiceImpl<DbMonitorWorkorderRecordMapper, DbMonitorWorkorderRecord> implements DbMonitorWorkorderRecordService {

    /**
     * 生成工单处置记录
     * @param orderId 工单编号
     * @param record 处置记录
     * @param userid 操作用户编号
     */
    @Override
    public void createWorkorderRecord(Long orderId, DbMonitorWorkorderRecord record, String userid){
        LocalDateTime time = LocalDateTime.now();
        record.setOrderId(orderId);
        record.setUpdatedBy(userid);
        record.setUpdatedTime(time);
        record.setCreatedBy(userid);
        record.setCreatedTime(time);
        record.setIsDelete(0);
        baseMapper.insert(record);
    }

    /**
     * 通过工单编号查询处置记录
     * @param orderId 工单编号
     * @return
     */
    @Override
    public List<DbMonitorWorkorderRecord> queryWorkorderRecordListByOrderId(Long orderId){
        QueryWrapper<DbMonitorWorkorderRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        wrapper.eq("order_id",orderId);
        List<DbMonitorWorkorderRecord> list = baseMapper.selectList(wrapper);
        return list;
    }

    /**
     *
     * 格式化工单处置记录
     * @param record
     */
    @Override
    public Map<String, Object> formatMonitorWorkorderRecord(DbMonitorWorkorderRecord record) {
        HashMap<String, Object> map = new HashMap<>();
        if (record.getDealTime() != null){
            map.put("dealTime", DateUtils.formatNormal(record.getDealTime()));
        }else {
            map.put("dealTime","");
        }
        map.put("dealDept",record.getDealDept());
        map.put("dealUser",record.getDealUser());
        map.put("dealIdcard",record.getDealIdcard());
        map.put("dealDesc",record.getDealDesc());
        return map;
    }
}
